#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,l,v;
int d[3010],a[3010],b[3010],x[3010],c[3010][3010],cnt[3010];
double s[3010];
bool cmp(int y,int z){
    return y>z;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        int summ1=0,summ2=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>a[i]>>b[i];
            if(b[i]==0){
                if(a[i]<=v){
                    s[i]=l+1;
                }
                else s[i]=0;
            }
            else {
                if(b[i]>0){
                    s[i]=((v*v*1.0)-(a[i]*a[i]*1.0))/(2*b[i]*1.0)+d[i];
                }
                else{
                    s[i]=-(((v*v*1.0)-(a[i]*a[i]*1.0))/(2*b[i]*1.0)+d[i]);
                }
            }
        }

        for(int i=1;i<=m;i++){
            cin>>x[i];
        }
        sort(x+1,x+m+1);
        int minn=1e9;
        for(int i=1;i<=n;i++){
            bool f=false;
            for(int j=1;j<=m;j++){
                if(s[i]>=0){
                    if(x[j]>s[i]){
                        f=true;
                        c[i][++cnt[i]]=j;
                    }
                }
                else{
                    if(x[j]>=d[i]&&x[j]<=abs(s[i])){
                        c[i][++cnt[i]]=j;
                        f=true;
                    }
                }
            }
            if(f==true){
                summ1++;
            }
        }
        cout<<summ1<<" "<<m<<endl;
    }
    return 0;
}
